package com.huawei.appgallery.appcomment.ui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import com.huawei.appgallery.appcomment.impl.bean.UserCommentInfoCardBean;
import com.huawei.appgallery.appcomment.ui.usercomment.UserCommentInfoCard;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import o.bcb;
import o.bcg;
import o.bcg.h;
import o.bcg.i;
import o.bcw;
import o.bda;
import o.bdm.e;
import o.bdq;
import o.bdr;
import o.bdz;
import o.bec;
import o.bmt;
import o.cdh;
import o.cfw;
import o.cgs;
import o.chz;
import o.cih;
import o.cks;
import o.cku;
import o.ckv;
import o.cvt;
import o.ll;

public class UserCollectionListFragment extends AppListFragment<AppListFragmentProtocol> {
    private static String ᐝ = "forum|user_detail_review_favorite";
    private bec ˊ;
    private final BroadcastReceiver ॱॱ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ UserCollectionListFragment ˏ;

        {
            this.ˏ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            SafeIntent safeIntent = new SafeIntent(intent);
            Serializable serializableExtra;
            if ("com.huawei.appmarket.service.broadcast.Approved".equals(safeIntent.getAction())) {
                try {
                    serializableExtra = safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_APPROVED");
                    if (serializableExtra != null && (serializableExtra instanceof e)) {
                        this.ˏ.ˊ.ˏ((e) serializableExtra, this.ˏ.י);
                    }
                } catch (Throwable e) {
                    bcb.ˋ.ˊ("MyCommentListFragment", "ACTION_COMMENT_APPROVED error!!", e);
                }
            } else if ("com.huawei.appmarket.service.broadcast.CommentReplyAdded".equals(safeIntent.getAction())) {
                try {
                    this.ˏ.ˊ.ˋ(safeIntent.getStringExtra("ACTION_PARAM_COMMENT_REPLY_ADDED_TYPE_COMMENTID"), safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_APPID"), this.ˏ.י);
                } catch (Throwable e2) {
                    bcb.ˋ.ˊ("MyCommentListFragment", "ACTION_COMMENT_REPLY_ADDED error!!!", e2);
                }
            } else if ("com.huawei.appmarket.service.broadcast.CommentAdded".equals(safeIntent.getAction())) {
                this.ˏ.ˊ.ॱ(safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_APPID"), safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_RATING"), safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_CONTENT"), this.ˏ.י);
            } else if ("com.huawei.appmarket.service.broadcast.CommentCollect".equals(safeIntent.getAction())) {
                this.ˏ.ॱ(safeIntent.getStringExtra("ACTION_PARAM_COMMENT_CANCEL_COLLECT_TYPE_COMMENTID"));
            } else if ("com.huawei.appmarket.service.broadcast.Dissed".equals(safeIntent.getAction())) {
                try {
                    serializableExtra = safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_DISSED");
                    if (serializableExtra != null && (serializableExtra instanceof e)) {
                        this.ˏ.ˊ.ˏ((e) serializableExtra, this.ˏ.י);
                    }
                } catch (Throwable e22) {
                    bcb.ˋ.ˊ("MyCommentListFragment", "ACTION_COMMENT_DISS error!!", e22);
                }
            }
        }
    };

    class a implements bdz {
        final /* synthetic */ UserCollectionListFragment ˊ;
        cih ˎ;

        public a(UserCollectionListFragment userCollectionListFragment, cih o_cih) {
            this.ˊ = userCollectionListFragment;
            this.ˎ = o_cih;
        }

        public void ˊ() {
            this.ˊ.ˏ(this.ˎ);
        }

        public void ˋ() {
        }
    }

    class c implements OnMenuItemClickListener {
        String ˎ;
        final /* synthetic */ UserCollectionListFragment ˏ;

        public c(UserCollectionListFragment userCollectionListFragment, String str) {
            this.ˏ = userCollectionListFragment;
            this.ˎ = str;
        }

        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == bcg.e.ʽˊ) {
                this.ˏ.ˎ(this.ˎ);
            }
            return false;
        }
    }

    public static UserCollectionListFragment ˊʻ() {
        return new UserCollectionListFragment();
    }

    private void ॱ(String str) {
        if (this.י != null && !TextUtils.isEmpty(str)) {
            for (chz o_chz : this.י.ʻॱ()) {
                if (!(o_chz == null || cgs.ˋ(o_chz.ˎ))) {
                    List list = o_chz.ˎ;
                    Iterator it = list.iterator();
                    while (it.hasNext()) {
                        BaseCardBean baseCardBean = (BaseCardBean) it.next();
                        if ((baseCardBean instanceof UserCommentInfoCardBean) && str.equals(((UserCommentInfoCardBean) baseCardBean).ˊ().ॱᐝ())) {
                            it.remove();
                            break;
                        }
                    }
                    this.י.ͺ();
                    if (list.size() == 0) {
                        ˋॱ(false);
                    }
                }
            }
        }
    }

    public void ˏ(Bundle bundle) {
        ˋॱ(102012);
        super.ˏ(bundle);
        this.ˊ = new bec(ॱˋ());
        this.ˏͺ = 5;
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View ˋ = super.ˋ(layoutInflater, viewGroup, bundle);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentAdded");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Approved");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Dissed");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentCollect");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentReplyAdded");
        ll.ˏ(ॱˋ()).ˏ(this.ॱॱ, intentFilter);
        return ˋ;
    }

    public void ᐝ() {
        super.ᐝ();
        ll.ˏ(ॱˋ()).ˋ(this.ॱॱ);
    }

    public void ॱ(NodataWarnLayout nodataWarnLayout) {
        if (nodataWarnLayout != null) {
            nodataWarnLayout.setWarnImage(o.bcg.c.ˊ);
            nodataWarnLayout.setWarnTextOne(h.ˏॱ);
            nodataWarnLayout.setViewVisible(NodataWarnLayout.e.WARN_BTN, 8);
            nodataWarnLayout.setViewVisible(NodataWarnLayout.e.WARN_TEXTTWO, 8);
        }
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        list.add(new bda(ᐝ, this.ˏ));
    }

    public void ˏ(int i, cih o_cih) {
        if (o_cih != null) {
            if (i == 1002) {
                ॱ(o_cih);
                return;
            }
            CardBean ˌ;
            if (i == 1003) {
                if (bmt.ˊ(ॱˋ())) {
                    ˌ = o_cih.ˌ();
                    if ((ˌ instanceof UserCommentInfoCardBean) && this.ˊ != null) {
                        this.ˊ.ˏ(ˌ);
                        return;
                    }
                }
                ckv.ˎ(ॱˋ().getString(h.ᐝʽ), 0);
                return;
            } else if (i == 1005) {
                ˌ = o_cih.ˌ();
                if (ˌ instanceof UserCommentInfoCardBean) {
                    ॱ(((UserCommentInfoCard) o_cih).ᐝ(), ((UserCommentInfoCardBean) ˌ).ˊ().ॱᐝ());
                    return;
                }
            } else if (i == 1008) {
                new bdr(ॱˋ(), new a(this, o_cih)).ˎ();
                return;
            }
            super.ˏ(i, o_cih);
        }
    }

    private boolean ˏ(cih o_cih) {
        if (bmt.ˊ(ॱˋ())) {
            CardBean ˌ = o_cih.ˌ();
            if ((ˌ instanceof UserCommentInfoCardBean) && (o_cih instanceof UserCommentInfoCard)) {
                UserCommentInfoCardBean userCommentInfoCardBean = (UserCommentInfoCardBean) ˌ;
                UserCommentInfoCard userCommentInfoCard = (UserCommentInfoCard) o_cih;
                if (this.ˊ != null) {
                    this.ˊ.ॱ(userCommentInfoCardBean, userCommentInfoCard, false);
                }
            }
            return false;
        }
        ckv.ˎ(ॱˋ().getString(h.ᐝʽ), 0);
        return true;
    }

    private void ॱ(cih o_cih) {
        if (bmt.ˊ(ॱˋ())) {
            CardBean ˌ = o_cih.ˌ();
            if ((ˌ instanceof UserCommentInfoCardBean) && (o_cih instanceof UserCommentInfoCard)) {
                UserCommentInfoCardBean userCommentInfoCardBean = (UserCommentInfoCardBean) ˌ;
                UserCommentInfoCard userCommentInfoCard = (UserCommentInfoCard) o_cih;
                if (this.ˊ != null) {
                    this.ˊ.ॱ(userCommentInfoCardBean, userCommentInfoCard, true);
                    return;
                }
                return;
            }
            return;
        }
        ckv.ˎ(ॱˋ().getString(h.ᐝʽ), 0);
    }

    private void ॱ(View view, String str) {
        if (view != null) {
            PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
            Menu menu = popupMenu.getMenu();
            popupMenu.getMenuInflater().inflate(i.ˎ, menu);
            menu.findItem(bcg.e.ʽˊ).setTitle(ॱˊ().getResources().getString(h.ͺ));
            popupMenu.setOnMenuItemClickListener(new c(this, str));
            popupMenu.show();
        }
    }

    private void ˎ(final String str) {
        Context ॱˋ = ॱˋ();
        if (ॱˋ != null) {
            CharSequence string = ॱˋ.getString(h.ᐧ);
            cku ˋ = cku.ˋ(null, ॱˋ.getString(h.ᐝॱ));
            ˋ.ˎ(ॱˋ);
            ˋ.ॱ(-1, string);
            ˋ.ॱ(new cks(this) {
                final /* synthetic */ UserCollectionListFragment ˏ;

                public void enableNetworking() {
                    this.ˏ.ˊ(str);
                }

                public void upgrade() {
                }

                public void ˋ() {
                }
            });
        }
    }

    private void ˊ(String str) {
        Context ʻॱ = AbstractBaseActivity.ʻॱ();
        if (ʻॱ == null) {
            bcb.ˋ.ˋ("MyCommentListFragment", "current Activity is null");
        } else if (bmt.ˊ(ʻॱ)) {
            cvt o_bcw = new bcw(str, 1);
            o_bcw.setServiceType_(cdh.ˎ(ʻॱ));
            cfw.ˎ(o_bcw, new bdq(null, str, 1, ʻॱ));
        } else {
            ckv.ˎ(ʻॱ.getString(h.ᐝʽ), 0);
        }
    }
}
